home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / WINDOWS.C < prev    next >
C/C++ Source or Header  |  1992-02-25  |  8KB  |  265 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Module to handle the windows used by the solid modeller.             *
  7. *****************************************************************************/
  8.  
  9. #ifdef __MSDOS__
  10. #include <alloc.h>
  11. #include <conio.h>
  12. #include <dos.h>
  13. #endif /* __MSDOS__ */
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include "program.h"
  19. #include "graphgen.h"
  20. #include "viewobj.h"
  21. #include "windows.h"
  22.  
  23. #define IRIT_PROMPT    "Irit> "
  24.  
  25. #ifdef __MSDOS__
  26.  
  27. /* Set it to FALSE if the status window is used for other purpose (such as */
  28. /* for interactive transformation (INTERACT command)).               */
  29. static int UpdateStatusWindow = TRUE;
  30.  
  31. #endif /* __MSDOS__ */
  32.  
  33. /*****************************************************************************
  34. *  Routine to toggle the input window log file printing. If turned on, test  *
  35. * is made if file has been opened and if not open it.                 *
  36. *****************************************************************************/
  37. void WndwLogPrint(RealType *Set)
  38. {
  39.     char s[LINE_LEN];
  40.  
  41.     if (APX_EQ(*Set, 0.0)) {
  42.     GlblPrintLogFile = FALSE;
  43.     fflush(GlblLogFile);
  44.     return;
  45.     }
  46.  
  47.     if (GlblLogFile == NULL) {              /* Not open yet - open it now: */
  48.     if ((GlblLogFile = fopen(GlblLogFileName, "w")) == NULL) {
  49.         sprintf(s, "Failed to open log file \"%s\"", GlblLogFileName);
  50.         WndwInputWindowPutStr(s);
  51.         return;
  52.     }
  53.     GlblPrintLogFile = TRUE;
  54.     }
  55. }
  56.  
  57. /*****************************************************************************
  58. *  Routine to wait for user keystroke while drawing blinking cursor:         *
  59. * No data is returned - used as pause only.                     *
  60. *****************************************************************************/
  61. void WndwPause(RealType *R)
  62. {
  63. #ifdef __MSDOS__
  64.     if (!APX_EQ(*R, 0.0)) while (kbhit()) getch();         /* Flush stdin. */
  65.     WndwInputWindowPutStr("Type return to continue:");
  66.     getch();
  67. #else
  68. #ifdef DJGCC
  69.     if (!APX_EQ(*R, 0.0)) while (kbhit()) getkey();         /* Flush stdin. */
  70.     WndwInputWindowPutStr("Type return to continue:");
  71.     getkey();
  72. #else
  73.     fprintf(stderr, "Type return to continue:");
  74.     getchar();
  75. #endif /* DJGCC */
  76. #endif /* __MSDOS__ */
  77. }
  78.  
  79. /*****************************************************************************
  80. *  Routine to handle the text on the Input Window. This window echoes all    *
  81. * the input steam - the input parser input. Errors or information is also    *
  82. * displayed in this window.                             *
  83. *****************************************************************************/
  84. void WndwInputWindowPutStr(char *Msg)
  85. {
  86.     char c, str[LINE_LEN_LONG];
  87.     int i;
  88.  
  89.     for (i = 0; *Msg != 0; Msg++) {
  90.     if (*Msg == 0x09)
  91.         do {
  92.         str[i++] = ' ';
  93.         }
  94.         while (i % 8 != 0);
  95.     else if (*Msg < ' ' || *Msg > '~')
  96.         break;
  97.     else
  98.         str[i++] = *Msg;
  99.     }
  100.     str[i] = 0;
  101.  
  102.     if (GlblPrintLogFile) fprintf(GlblLogFile, "%s\n", str);
  103.  
  104. #if defined(__MSDOS__) || defined(DJGCC)
  105.     if (GlblDoGraphics) {
  106. #ifdef __MSDOS__
  107.     if (kbhit())            /* Test and handle Control S/Q protocol. */
  108.         if ((c = getch()) == '\x13')            /* Its Ctrl - s. */
  109.         while (getch() != '\x11');           /* Wait for Ctrl - q. */
  110.         else
  111.         ungetch(c);
  112. #endif /* __MSDOS__ */
  113.  
  114.     IntrPrintf(InputWindowID, TRUE, str);
  115.     }
  116.     else {
  117.     printf("%s\n", str);
  118.     }
  119. #else
  120.     printf("%s\n", str);
  121. #endif /* __MSDOS__ || DJGCC */
  122. }
  123.  
  124. /*****************************************************************************
  125. *  Routine to handle reading one line from stdin into string Str, with max.  *
  126. * length Length in the Input Window.                         *
  127. *  Note Str may be non empty and can be used to fix wrong entry.         *
  128. *****************************************************************************/
  129. void WndwInputWindowGetStr(char *Str, int Length)
  130. {
  131. #ifdef __MSDOS__
  132.     if (GlblDoGraphics) {
  133.     Str[0] = 0;
  134.         IntrGetLineWindow(InputWindowID, Str, Length);
  135.     }
  136.     else {
  137.     int i;
  138.     char TLine[LINE_LEN_LONG];
  139.     union REGS regs;
  140.     struct SREGS sregs;
  141.  
  142.         printf(IRIT_PROMPT);
  143.  
  144.     TLine[0] = LINE_LEN_LONG - 2;
  145.     regs.x.dx = FP_OFF(TLine);
  146.     sregs.ds = FP_SEG(TLine);
  147.     regs.h.ah = 0x0a;
  148.     intdosx(®s, ®s, &sregs);
  149.     printf("\n");
  150.  
  151.         if (feof(stdin)) MyExit(0);/* Eof typed on keyboard (usually CtrlD). */
  152.     for (i = TLine[1] + 2; i > 1; i--)
  153.             if (TLine[i] <= ' ') TLine[i] = 0;
  154.     strncpy(Str, &TLine[2], Length - 1);
  155.     }
  156. #else
  157. #ifdef DJGCC
  158.     if (GlblDoGraphics) {
  159.     Str[0] = 0;
  160.         IntrGetLineWindow(InputWindowID, Str, Length);
  161.     }
  162.     else {
  163.     printf(IRIT_PROMPT);
  164.     fgets(Str, Length - 1, stdin);
  165.     if (feof(stdin)) MyExit(0);/* Eof typed on keyboard (usually CtrlD). */
  166.     if (Str[strlen(Str) - 1] < ' ') Str[strlen(Str) - 1] = 0;/* No CR/LF.*/
  167.     puts(Str);
  168.     } 
  169. #else
  170.     printf(IRIT_PROMPT);
  171.     fgets(Str, Length - 1, stdin);
  172.     if (feof(stdin)) MyExit(0);    /* Eof typed on keyboard (usually CtrlD). */
  173.     if (Str[strlen(Str) - 1] < ' ') Str[strlen(Str) - 1] = 0;   /* No CR/LF. */
  174.     puts(Str);
  175. #endif /* DJGCC */
  176. #endif /* __MSDOS__ */
  177. }
  178.  
  179. #ifdef __MSDOS__
  180.  
  181. /*****************************************************************************
  182. *  Routine to claim/reclaim control on the status window, so that it would   *
  183. * not be updated. Used by other modules to display data on the status window *
  184. * temporary, such as the INTERACT command - objects transformations.         *
  185. *****************************************************************************/
  186. void WndwClaimStatus(void)
  187. {
  188.     UpdateStatusWindow = FALSE;
  189. }
  190.  
  191. void WndwReclaimStatus(void)
  192. {
  193.     UpdateStatusWindow = TRUE;
  194. }
  195.  
  196. /*****************************************************************************
  197. *  Routine to handle the status window dynamic update - only reprint new.    *
  198. *****************************************************************************/
  199. void WndwStatusWindowUpdate(void)
  200. {
  201.     static char *AdvanceChar = "-\\|/";
  202.     static int AdvanceCount = 0;
  203.     static char CoreLine[11] = { 0 };
  204.  
  205.     if (!UpdateStatusWindow || !GlblDoGraphics) return;
  206.  
  207.     GRPushViewPort();
  208.     if (!IntrWndwIsAllVisible(StatusWindowID))
  209.     IntrWndwPop(StatusWindowID, TRUE, TRUE);
  210.     else
  211.     IntrWndwPop(StatusWindowID, FALSE, FALSE);
  212.     
  213.     GRPushTextSetting();
  214.     GRSetTextJustify(CENTER_TEXT, CENTER_TEXT);       /* Draw strings centered. */
  215.  
  216.     GGMySetColor(BLACK);                   /* Erase old version. */
  217.     IntrWndwRText(0.0, 0.6, CoreLine);
  218.  
  219.     /* Preper the new data to display: */
  220.     AdvanceCount = (AdvanceCount + 1) & 0x03;
  221.     sprintf(CoreLine, "%c %3dk %c",
  222.     AdvanceChar[AdvanceCount],
  223.     (int) (coreleft()/1024L),
  224.     AdvanceChar[AdvanceCount]);
  225.  
  226.     GGMySetColor(MAGENTA);                    /* Draw old version. */
  227.     IntrWndwRText(0.0, 0.6, CoreLine);
  228.  
  229.     GRPopTextSetting();
  230.  
  231.     GRPopViewPort();
  232. }
  233.  
  234. #endif /* __MSDOS__ */
  235.  
  236. /*****************************************************************************
  237. *  Routine to handle the view on the View Window. This routine displays      *
  238. * object(s) and prints its/their name also.                     *
  239. * If ClearWindow is not zero then the window is cleared first.             *
  240. *****************************************************************************/
  241. void WndwViewGeomObject(ObjectStruct *PObjList, RealType *ClearWindow)
  242. {
  243.     if (!GlblDoGraphics) return;
  244.  
  245.     if (!APX_EQ(*ClearWindow, 0.0)) {
  246.     GGClearViewArea();
  247.     }
  248.     else {
  249.     /* On SGI 4D with double buffer we want to draw on current window,   */
  250.     /* so it is swap temporarily as a back plane and will be swapped     */
  251.     /* back as front visible one after the drawing is complete.          */
  252. #if defined(__MSDOS__) || defined(DJGCC)
  253.     IntrWndwPop(ViewWindowID, FALSE, TRUE);
  254. #else
  255.     GGGraphicFlush();
  256. #endif /* __MSDOS__ || DJGCC */
  257.     }
  258.  
  259.     ViewGeomObject(PObjList);              /* And finally display it. */
  260.  
  261. #if !defined(__MSDOS__) && !defined(DJGCC)
  262.     GGGraphicFlush();
  263. #endif /* !__MSDOS__ && !DJGCC */
  264. }
  265.